package net.mikoo.seals.api.model.party;

import java.util.ArrayList;
import java.util.List;

import net.mikoo.seals.api.model.BaseResponse;
import net.mikoo.seals.model.Party;

public class SearchResponse extends BaseResponse {

	private static final long serialVersionUID = 4164830987803202754L;

	private List<PartyInfo> partyInfos;

	public List<PartyInfo> getPartyInfos() {
		return partyInfos;
	}

	public void setPartyInfos(List<PartyInfo> partyInfos) {
		this.partyInfos = partyInfos;
	}
	
	public static SearchResponse valueOf(List<Party> partyList) {
		SearchResponse result = new SearchResponse();
		if(partyList == null || partyList.isEmpty()) {
			return result;
		}
		
		List<PartyInfo> partyInfoList = new ArrayList<PartyInfo>();
		for(Party party : partyList) {
			if(party == null) {
				continue;
			}
			
			PartyInfo partyInfo = new PartyInfo();
			partyInfo.setPartyId(party.getPartyId());
			partyInfo.setLoginName(party.getUserLoginId());
			if(party.getPerson() != null) {
				partyInfo.setName(party.getPerson().getName());
				partyInfo.setPortrait(party.getPerson().getPortrait());
				partyInfo.setPosition(party.getPerson().getPosition());
			}
			partyInfoList.add(partyInfo);
		}
		
		result.setPartyInfos(partyInfoList);
		return result;
	}
}
